package cz.muni.fi.pa165.validate;

import java.util.ResourceBundle;
import javax.enterprise.context.ApplicationScoped;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;
import javax.inject.Named;

/**
 *
 * @author <a href="mailto:vramik at redhat.com">Vlastislav Ramik</a>
 */
@ApplicationScoped
@Named
public class PackageValidator {
    
    public void validateDimension(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        ResourceBundle res = ResourceBundle.getBundle("i18n.main", FacesContext.getCurrentInstance().getViewRoot().getLocale());
        if(!(value instanceof String)) {
            FacesMessage message = new FacesMessage(res.getString("error.form.must.string.name"));
            throw new ValidatorException(message); 
        }
        
        
        String val = (String)value;
        
        if(val.length() < 3) {
            FacesMessage message = new FacesMessage(res.getString("error.form.empty.field"));
            throw new ValidatorException(message); 
        }
    }
}
